/*
 * MinuteTimer.h
 *
 *  Created on: 2020年1月11日
 *      Author: terry
 */

#ifndef MINUTETIMER_H_
#define MINUTETIMER_H_

#include "BasicType.h"
#include <functional>
#include "TThread.h"
#include "TCriticalSection.h"
#include "TEvent.h"


class MinuteTimer : public comn::Thread
{
public:
	typedef std::function< void (int64_t time, int mday, int hour) >				HourHandler;
	typedef std::function< void(int64_t time, int mday, int hour, int minute) >	MinuteHandler;

	

	static const int DEF_INTERVAL;

public:
	MinuteTimer();
	virtual ~MinuteTimer();

	void setMinuteHandler(MinuteHandler handler);
	void setHourHandler(HourHandler handler);

	bool open();
	void close();
	bool isOpen();

	void resetTime();


protected:
	virtual int run();
	virtual void doStop();

	int64_t getClock();

	int checkTime();

	void fireMinute(int64_t clock, int mday, int hour, int minute);
	void fireHour(int64_t clock, int mday, int hour);

protected:
	MinuteHandler	m_minuteHandler;
	HourHandler	m_hourHandler;
	comn::Event	m_event;



};

#endif /* MINUTETIMER_H_ */
